/*
 * optimal.h
 *
 *  Created on: 17 sept. 2013
 *      Author: the
 */

#ifndef OPTIMAL_H_
#define OPTIMAL_H_
#include "type.h"
#include "metric.h"
#include "init.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//Global extern variables
extern int nbOfNodes;		//Number of nodes
extern struct node* nodes;	//Array with the nodes
extern int nbOfRadios;		//Number of radios per node
extern int maxFreq;		//Number of orthogonal frequencies
extern int algorithm;		//Algorithm number used to allocate the frequencies
extern float	L;		//Length of a side of the observation window (LxL)
extern float	R;		//Radio scope of the nodes

int minConflict;
struct node* copyNodes;	//Array with the a copy of the nodes (keeps the optimal assignment)



int computeOptimal();

//Algorithme recursif qui explore toutes les allocations possibles
//et sauvegarde l'optimal dans copyNodes
void allocateOptimal(int id, int radio, int minFreq);

//Algorithme recursif qui explore toutes les allocations possibles
//et sauvegarde l'optimal dans copyNodes
//La difference avec la premiere version est que l'on s'arrete des que l'on a une topologie qui
//preserve la topology. Toutes les radios ne sont donc pas forcement assignees comme pour l'autre.
void allocateOptimal2(int id, int radio, int minFreq);

void allocationFreq(int id, int radio, int freq);

void freeRadio2(int id, int radio);


//Retourne 1 si l'assignation actuelle est "topology" preserving
//Retourne 0 autrement (il y a deux voisins du graphe initiale qui n'ont pas de frequences en commun).
int preserveTopology();

//Verify that the node id, has a link with all its neighbors.
//We checck only if node id has all its radios assigned and only
//for neighbors with all their radios assigned.
int verifyConstraints(int id);

//Return the number of radios assigned (!=-1) to node id.
int nbOfAllocatedRadio(int id);


void saveTopology(struct node* source, struct node* destination);


#endif /* OPTIMAL_H_ */
